package ru.jexp.rcp.supply.view;

import java.util.List;

import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.swt.widgets.Composite;

import ru.jexp.obekt.identifikacia.IIdentificiruemii;
import ru.jexp.rcp.supply.viewer.JExpTreeLabelProvider;
import ru.jexp.rcp.supply.viewer.JExpTreeViewer;

public abstract class JExpViewPartTree extends JExpViewPart {

	protected abstract JExpTreeLabelProvider createTreeLabelProvider();
	
	protected abstract TreeNode[] tarnsform(List result);
	
	protected abstract TreeNode prepareToViewer(Object editBean, int action);
	
	public JExpViewPartTree(String nameView) {
		super(nameView);
	}
	
	@Override
	public void updateViewer(Object editBean, int action) {
		getTreeViewer().updateViewer(action, prepareToViewer(editBean, action));
	}
	

	@Override
	protected IIdentificiruemii prepareToOpen(Object inViewer) {
		return (IIdentificiruemii) ((TreeNode)inViewer).getValue();
	}
	
	@Override
	protected IIdentificiruemii prepareToDelete(Object inViewer) {
		return (IIdentificiruemii) ((TreeNode)inViewer).getValue();
	}
	
	@Override
	protected ColumnViewer createViwer(Composite parent) {
		return new JExpTreeViewer(parent, createTreeLabelProvider());
	}

	protected final JExpTreeViewer getTreeViewer() {
		return (JExpTreeViewer) getViewer();
	}

	@Override
	protected Object prepareToViewer(List result) {
		return tarnsform(result);
	}
}
